import requests
from bs4 import BeautifulSoup
import re
import urllib
import time
import urllib2
import time
headers = {'user_agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
for i in range(0,5):
 url = "https://bbs.hupu.com/bxj-"+str(i)
 print url
 try:
  r = requests.get(url,headers,timeout=10) 
 except urllib.URLError,e:
  print e.reason
 except urllib2.HTTPError,e:
  print e.reason 
 else:
  print(str(i+1),"status:",r.status_code)
  html = r.text
 soup = BeautifulSoup(html,'html.parser')
 titles = soup.find_all('a',class_="truetit")
 authors = soup.find_all('a',class_="aulink")
 replies = soup.find_all('span',class_="ansour box")
 hrefs = []
 for link in soup.find_all('a',class_="aulink"):
  hrefs.append(link.get('href'))
 for i in range(0,len(titles)):
  print("********************")
  print("title:"+titles[i].text.strip())
  print("author:"+authors[i].text.strip())
  print("reply:"+replies[i].text.strip())
  print("href:"+hrefs[i])
  print("********************")
